﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class SolutionFuturetwoSum
{
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @param target int整型 
     * @return int整型一维数组
     */
    public List<int> twoSum(List<int> nums, int target)
    {
        // write code here
        //使用字典记录数字和i
        List<int> res = new List<int>();
        Dictionary<int,int> map = new Dictionary<int,int>();
        for (int i = 0; i < nums.Count; i++)
        {
            if (map.ContainsKey(nums[i]))
            {

                res.Add(map[nums[i]]);
                res.Add(i);
            }
            else
            {
                map.Add(target- nums[i], i);
            }

        }

        return res;


    }
}
class ProgramFuturetwoSum
{
    static void MainFuturetwoSum(string[] args)
    {
        SolutionFuturetwoSum solutionFuturetwoSum = new SolutionFuturetwoSum();
        List<int> nums = new List<int>{ 1, -2, -3, -4 };
        List<int> res= solutionFuturetwoSum.twoSum(nums,-5);
        for (int i = 0; i < res.Count; i++)
        {
            Console.WriteLine(res[i]);
        }
    }
}
